import { uuid } from '../../utils/uuid';
import { YmFilePathContextType } from './interface';

/**
 * @desc 运脉文件路径生成规则
 */
export function YmFilePathRule({
  client,
  system,
  ext,
  busPath,
  phone,
}: YmFilePathContextType & {
  ext?: string;
  busPath?: string;
}) {
  const date = new Date();
  const YYYY = date.getFullYear() + '';
  const MM = `0${date.getMonth()}`.slice(-2);
  const DD = `0${date.getDate()}`.slice(-2);
  const HH = `0${date.getHours()}`.slice(-2);
  const mm = `0${date.getMinutes()}`.slice(-2);

  return `${client}/${phone ?? 'default'}/${busPath ?? 'default'}/${
    YYYY + MM
  }/${YYYY + MM + DD}_${HH + mm}_${uuid()}_${system}.${ext}`;
}
